using System.Text;
using System.Web.Mvc;

namespace Blog.Helper
{
    public static class HtmlExtensions
    {
        public static string RichTextInit(this HtmlHelper html, string elementId, string theme)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<script type=\"text/javascript\">");
            sb.Append("tinyMCE.init({");
            sb.AppendFormat("mode : \"{0}\",", "exact");
            sb.AppendFormat("plugins: '{0}',", "advimagescale,media,paste");
            sb.Append("advimagescale_max_height: 1024, ");
            sb.Append("advimagescale_max_width:  380,");
            sb.Append("advimagescale_min_height: 20, ");
            sb.Append("advimagescale_min_width:  20,");
            sb.AppendFormat("theme : \"{0}\",", theme);        // theme - DUCVD Changed
            sb.AppendFormat("skin : \"{0}\",", "default");
            sb.AppendFormat("theme_advanced_toolbar_location : \"{0}\",", "top");
            sb.AppendFormat("theme_advanced_toolbar_align : \"{0}\",", "left");
            sb.AppendFormat("theme_advanced_statusbar_location : \"{0}\",", "bottom");
            sb.AppendFormat("theme_advanced_resizing : {0},", "true");
            sb.AppendFormat("cleanup : {0},", "true");
            sb.AppendFormat("theme_advanced_buttons1_add : '{0}',", "media,|,styleselect,formatselect,fontselect,fontsizeselect");

            sb.AppendFormat("theme_advanced_buttons2_add : '{0}',", "pastetext,pasteword");

            sb.AppendFormat("elements : \"{0}\"", elementId);
            sb.Append("});");
            sb.Append("</script>");

            return sb.ToString();
        }
        public static string RichTextInitForFrontEnd(this HtmlHelper html, string elementId, string theme)
        {
            StringBuilder sb = new StringBuilder();

            //sb.Append("<script type=\"text/javascript\">");
            //sb.Append("tinyMCE.init({");
            //sb.AppendFormat("mode : \"{0}\",", "exact");
            //sb.AppendFormat("plugins: '{0}',", "paste");
            //sb.Append("advimagescale_max_height: 1024, ");
            //sb.Append("advimagescale_max_width:  380,");
            //sb.Append("advimagescale_min_height: 20, ");
            //sb.Append("advimagescale_min_width:  20,");
            //sb.AppendFormat("theme : \"{0}\",", theme);        // theme - DUCVD Changed
            //sb.AppendFormat("skin : \"{0}\",", "default");
            //sb.AppendFormat("theme_advanced_toolbar_location : \"{0}\",", "top");
            //sb.AppendFormat("theme_advanced_toolbar_align : \"{0}\",", "left");
            //sb.AppendFormat("theme_advanced_statusbar_location : \"{0}\",", "bottom");
            //sb.AppendFormat("theme_advanced_resizing : {0},", "true");
            //sb.AppendFormat("cleanup : {0},", "true");
            //sb.AppendFormat("theme_advanced_buttons1_add : '{0}',", "styleselect,formatselect,fontselect,fontsizeselect");
            //sb.AppendFormat("theme_advanced_buttons3_add : '{0}',", "pastetext,pasteword,selectall");
            //sb.AppendFormat("theme_advanced_disable : '{0}',", "image");

            //sb.AppendFormat("elements : \"{0}\"", elementId);
            //sb.Append("});");
            //sb.Append("</script>");

            sb.Append("<script type=\"text/javascript\">");
            sb.Append("tinyMCE.init({");
            sb.Append("convert_urls : false,");
        sb.Append("mode : \"textareas\",");
        sb.Append("theme : \"advanced\",");
        sb.Append("entities : \"160,nbsp,34,quot,162,cent,8364,euro,163,pound,165,yen,169,copy,174,reg,8482,trade,8240,permil,60,lt,62,gt,8804,le,8805,ge,176,deg,8722,minus\",");
            sb.Append("button_tile_map : true,");
            sb.Append("width : \"540\",");
            sb.Append("height : \"400\",");
        sb.Append("plugins : \"zd_advimage,fullscreen,visualchars,table,paste\",");
        sb.Append("theme_advanced_buttons1 : \"undo,redo,removeformat,|,formatselect,|,bold,italic,underline,strikethrough,sub,sup,|,outdent,indent,bullist,numlist,hr|,link,unlink,charmap,");
        sb.Append("image");
        sb.Append("\",");
        sb.Append("theme_advanced_buttons2 : \"cut,copy,paste,pastetext,pasteword,separator,tablecontrols,separator,cleanup,");
        sb.Append("code,");
        sb.Append("fullscreen\",");
        sb.Append("theme_advanced_buttons3 : \"\",");
        sb.Append("theme_advanced_toolbar_location : \"top\",");
        sb.Append("theme_advanced_toolbar_align : \"left\",");
        sb.Append("theme_advanced_path_location : \"bottom\",");
        sb.Append("theme_advanced_blockformats : \"p,h1,h2,h3,h4,blockquote\",");
        sb.Append("gecko_spellcheck : true,");
        sb.Append("extended_valid_elements : \"a[name|href|target|title|onclick],img[class|src|style|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],span[class|align|style],font[],form[name|id|action|method],input[type|name|value],iframe[src|style|width|height],script[src]\",");
        sb.Append("theme_advanced_resizing : true,");
        sb.Append("theme_advanced_resize_horizontal : false,");
            sb.Append("body_class : \"user_formatted entry content\",");            
            sb.Append("content_css : \"/stylesheets/zd_all_users.css?version=128\"");
    sb.Append("});");
            sb.Append("</script>");

            return sb.ToString();
        }
    }
}